import 'dart:convert';

import 'package:flutter/widgets.dart';
import 'package:x3_base_package/x3_base_package.dart';

class BusinessAttributeModel {
  BusinessAttributeModel({
    @required this.title,
    @required this.itemList,
  });

  factory BusinessAttributeModel.fromJson(Map<String, dynamic> jsonRes) {
    final List<AttributeItemModel> attributes = <AttributeItemModel>[];
    for (final dynamic item in jsonRes['itemList']) if (item != null) attributes.add(AttributeItemModel.fromJson(item));
    return BusinessAttributeModel(title: jsonRes['title'] ?? '', itemList: attributes);
  }

  String title;
  List<AttributeItemModel> itemList;

  Map<String, dynamic> toJson() => <String, dynamic>{'title': title, 'itemList': itemList};

  @override
  String toString() => json.encode(this);
}

class AttributeItemModel {
  AttributeItemModel({this.showCopied = false, this.showColon = true, @required this.attribute});

  factory AttributeItemModel.fromJson(Map<String, dynamic> jsonRes) {
    return AttributeItemModel(showCopied: jsonRes['showCopied'] ?? false, showColon: jsonRes['showColon'] ?? true, attribute: jsonRes['attribute'] ?? BaseKeyValueModel(key: '', value: ''));
  }

  bool showCopied;
  bool showColon;
  BaseKeyValueModel attribute;

  Map<String, dynamic> toJson() => <String, dynamic>{'showCopied': showCopied, 'showColon': showColon, 'attribute': attribute};

  @override
  String toString() => json.encode(this);
}
